<?php
namespace Home\Controller;

use Common\Controller\HomeBaseController;

class IndexController extends HomeBaseController
{
    public function index()
    {
//
        header('Content-Type: text/html; charset=utf8');
        //$this->display();
        $phone = '082112252069';
        //发送短信验证码
        $verify_code = rand(100, 999) . rand(100, 999);
        $param = array();
        $param['site_name'] = C('site_name');
        $param['send_time'] = date('Y-m-d H:i',time());
        $param['verify_code'] = $verify_code;
        cookie('verify_code', $verify_code, 3600);
        //$content = "欢迎使用使用黄金钱包平台，您的验证码为：" . $verify_code . "【融信恒创信息科技有限公司】";
        $content = "SELAMAT DATANG MENGGUNAKAN APLIKASI KANTONG EMAS，您的验证码为：" . $verify_code . "【KODE VERIFIKASI ANDA ADALAH】";
        vendor('Sms.sms');
        $sms = new \sms();
        $result = $sms->send(1, $content, $phone);
        var_dump($result);
        exit;
        if ($result) {
            echo 123;
            exit;
        } else {
            echo 456;
            exit;
        }

        $admin = 'root';
        $password = '123456';
        if (!$admin || !$password) {
            $this->apiError('用户名或密码不完整');
        }

        /*$where['admin'] = $admin;
        $where['password'] = admin_md5($password);
        $where['status'] = 1;
        $res = M('company_management')->where($where)->find();
        echo M('company_management')->_sql();
        var_dump($res);
        exit;*/
    }


    public function chksubmit()
    {

        $_POST['verify_code'] = '340214';
        $result = chksubmit(false, true, 'num', true);

        if ($result) {
            if ($result === -11) {
                var_dump('非法请求');
                exit;
            } elseif ($result === -12) {
                var_dump('验证码错误！');
                exit;
            } elseif ($result === -13) {
                var_dump('手机验证码错误！');
                exit;
            }
            echo '验证码正确2323';
            //通过后的处理
        }
    }


    /**
     * 登录生成token
     */
    private function _get_token($member_id, $member_name)
    {
        //model
        $model_user_token = Model('user_token');

        //重新登录后以前的令牌失效
        $condition = array();
        $condition['member_id'] = $member_id;
        $model_user_token->delMbUserToken($condition);

        //生成新的token
        $user_token_info = array();
        $token = md5($member_name . strval(time()) . strval(rand(0, 999999)));
        $user_token_info['member_id'] = $member_id;
        $user_token_info['member_name'] = $member_name;
        $user_token_info['token'] = $token;
        $user_token_info['login_time'] = time();
        $result = $model_user_token->addMbUserToken($user_token_info);
        if ($result) {
            return $token;
        } else {
            return null;
        }

    }


}